<?php

/**
 * 这个是获取 首页配置的文件
 */
 
global $_GPC, $_W; 
 
$uniacid = $this->_uniacid;
$uid = $_W['member']['uid']; 
$openid = $_W['openid'];
$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
$selects = $this->_forms;
/*按placeid获取配置*/
if($operation =='display'){

    $place = $_GPC['placeids'];
    $params = array();
    $params['confmenu'] = array();
    $params['confmenu']['index'] = 0;
    
    $ret = pdo_fetchall("select * from ".  tablename("kbwdl_config")." where uniacid='$uniacid' and placeid in($place) and module='kbwdl_shequzufang'");
    if(is_array($ret)){
        foreach($ret as $key =>$val){
            $params[$val['confkey']] = iunserializer($val['conf_value']);
        }
    }
    if(!isset( $params['confmenu']['floatmenu'] )){
         $params['confmenu']['floatmenu'] = 'default';
    }
     if(!isset( $params['confmenu']['index'] )){
         $params['confmenu']['index'] = 0;
    }
    /**
     * 处理底部导航
     */
    $navmenu = array();
 
    $menu['color'] =  '#8a8a8a';
    $menu['selectedColor'] =  '#F87271';
    $menu['borderStyle'] =  'white';
    $menu['backgroundColor'] =  '#f1f1f1';
    if($params['confmenu']['index']==1){         
        $navmenu = $params['navmenu'];
        $menu['color'] = $params['confmenu']['color'];
        $menu['selectedColor'] = $params['confmenu']['selectedColor'];
        $menu['borderStyle'] = $params['confmenu']['borderStyle'];
        $menu['backgroundColor'] = $params['confmenu']['backgroundColor'];
        foreach($navmenu as $key=>$val){
            if(!strstr($val['iconPath'], 'static')){
                $navmenu[$key]['iconPath'] = tomedia($val['iconPath']);               
            }
            if(!strstr($val['selectedIconPath'], 'static')){
                $navmenu[$key]['selectedIconPath'] = tomedia($val['selectedIconPath']);                
            }
            if($val['isshow']==1){              
                unset($navmenu[$key]);
            }
            
        }
    }
    unset($params['navmenu']);
    $params['btbaritem'] = array();//$navmenu;
    $params['btbar'] = $menu;
    /* === end */
}elseif($operation == 'tabbars'){
    /*获取底部tabbar*/
    $ret2 = pdo_fetch("select * from ".  tablename("kbwdl_config")." where uniacid='$uniacid' and placeid=11 and module='kbwdl_shequzufang'");
    $confmenu = iunserializer($ret2['conf_value']);   
    $ret = pdo_fetch("select * from ".  tablename("kbwdl_config")." where uniacid='$uniacid' and placeid=24 and module='kbwdl_shequzufang'");
     if($ret['conf_value']){
            $tabbars =  iunserializer($ret['conf_value']);
     }
    $params['tabbaropen'] = 0;
    if(isset($confmenu['tabbaropen']) &&  ($confmenu['tabbaropen']==1) ){
        $params['tabbaropen'] = 1;
    }
    $params['items'] = $tabbars; 
    /*样式*/
    $params['color'] = '';
    $params['selectedColor'] = '';
    $params['backgroundColor'] = '';
    
    if(isset($confmenu['tabbar']['color']) && !empty($confmenu['tabbar']['color'])){
         $params['color'] = trim($confmenu['tabbar']['color']);
    }
     if(isset($confmenu['tabbar']['selectedColor']) && !empty($confmenu['tabbar']['selectedColor'])){
         $params['selectedColor'] = trim($confmenu['tabbar']['selectedColor']);
    }
     if(isset($confmenu['tabbar']['backgroundColor']) && !empty($confmenu['tabbar']['backgroundColor'])){
         $params['backgroundColor'] = trim($confmenu['tabbar']['backgroundColor']);
    }
/*获取我的 页面 菜单配置信息*/
}elseif($operation == 'UserHomeMenu'){
    $userselect_default = [
            'broker_send'=> '发布租房出售商铺',
            'broker_quick'=> '经纪人管理助手',
            'broker_manage' => '我发布的房源',
            'broker_mysend' => '我发布的需求',
            'share_index' => '我的推广中心', /*海报推广*/
             'batch_index' => '经纪人推荐客户',/*经纪人推广*/           
            /*推荐客户模式*/           
            'charges_report'=>'报备客户进度处理',
            'charges_myuser'=> '我推荐的客户',
            'charges_feed'=> '收到的推荐信息',
            /**/
             'caculte_toos' => '房贷计算器',
        ];
      $perselect_default = [
            'jifen_name'=> '积分余额和房源数',
            'broker_send'=> '发布租房出售商铺',         
            'broker_manage' => '我发布的房源',
            'broker_mysend' => '我发布的需求',
            'share_index' => '我的推广中心', /*海报推广*/                
            /*推荐客户模式*/  
           'charges_myuser'=> '我推荐的客户',     
            /**/
            'caculte_toos' => '房贷计算器',
        ];
    /*userselect*/
    $ret = pdo_fetch("select * from ".  tablename("kbwdl_config")." where uniacid='$uniacid' and placeid=43 and module='kbwdl_shequzufang'");
    $userselect =  [];
    if(isset($ret['conf_value']) && !empty($ret['conf_value'])){
        $userselect = iunserializer($ret['conf_value']);
    }
    /*perselect*/
    $ret = pdo_fetch("select * from ".  tablename("kbwdl_config")." where uniacid='$uniacid' and placeid=44 and module='kbwdl_shequzufang'");
    $perselect =  [];
    if(isset($ret['conf_value']) && !empty($ret['conf_value'])){
        $perselect = iunserializer($ret['conf_value']);
    }
    foreach($userselect_default as $key => $val){
        if(empty($userselect[$key])){
            $userselect[$key] = $val;
        }
        $dk = $key."_disabled";
        if(!isset($userselect[$dk]) || empty($userselect[$dk])){
            $userselect[$dk] = 0;
        }
    }
   foreach($perselect_default as $key => $val){
        if(empty($perselect[$key])){
            $perselect[$key] = $val;
        }
         $dk = $key."_disabled";
        if(!isset($perselect[$dk]) || empty($perselect[$dk])){
            $perselect[$dk] = 0;
        }
    }
    /*获取充值开关是否开启*/
    $st = $this->_getSetting();
    $perselect['chognzhi'] = $st['chognzhi'];
    $userselect['chognzhi']= $st['chognzhi'];
    $params['perselect'] = $perselect;
    $params['userselect'] = $userselect;
    /*获取首页菜单*/
}elseif($operation =='navmenu'){
    $ret = pdo_fetch("select * from ".  tablename("kbwdl_config")." where uniacid='$uniacid' and placeid=1 and module='kbwdl_shequzufang'");
    $ret2 = pdo_fetch("select * from ".  tablename("kbwdl_config")." where uniacid='$uniacid' and placeid=11 and module='kbwdl_shequzufang'");
    $confmenu = iunserializer($ret2['conf_value']);
     
    /*默认菜单*/
    $navmenu = include  IA_ROOT.  "/addons/kbwdl_shequzufang/vender/menu.php";
     
    if(isset($confmenu['index']) && $confmenu['index']==1){
        if($ret['conf_value']){
            $navmenu =  iunserializer($ret['conf_value']);
        }
        foreach ($navmenu as $key=>$v){
            $tmp[$v['order']] = $v;
        }
        ksort($tmp);
        $navmenu = $tmp;
    } 
    $params = array();
    if(is_array($navmenu)){
        foreach($navmenu as $key =>$val){
            if($val['isshow']==1){
                $params[] = $val;
            }
        } 
    }
/*	$data['menu_cols'] = 5;
	$params = array();
	$ret = pdo_fetchall("select * from ".  tablename("kb_thread_forums")." where uniacid='$uniacid' AND type=1 and disabled=0 order by orderid desc,id");
    if(!empty($ret)){
		foreach($ret as $key => $val){
			$navmenu = iunserializer($val['setting']);
			if(  $val['islink'] ==1){
				$tmp['pathurl'] = $navmenu['linkurl'];
			}else{
				$tmp['pathurl'] =  '/kbwdl_shequzufang/pages/thread/dlist?id='.$val['id'];
			}
			$tmp['appid'] = '';
			$tmp['iconpic'] = tomedia($val['thumb']);
			$tmp['name'] = $val['fname'];
			$tmp['icon'] = 'icon-zonghe';
			$params[] = $tmp;
                        unset($tmp);
			
		}
	}
	*/
	
	/*保存forums id 用于发openid 模板*/
}elseif($operation =='saveformsid'){
    include  IA_ROOT.  "/addons/kbwdl_shequzufang/vender/mnshelper.php";
    $helper = new mnshelper();
    if(!empty($_W['openid'])){
       // $helper->saveFormIds($_W['openid'], $_GPC['formid']);
    }
    /**
     * 获取一个 可用的 formid $helper->getFormId($_W['openid'])；
     */
    $params = array('formid'=> 'ok' );
   
}elseif($operation =='adinfo'){
    /*获取首页广告*/
     $adplace = include  IA_ROOT.  "/addons/kbwdl_shequzufang/vender/adplace.php";
     foreach($adplace as $key =>$place){
         $ret = pdo_fetch("select * from ".  tablename("kbwdl_config")." where uniacid='$uniacid' and placeid=201 and confkey='$key' and module='kbwdl_shequzufang' order by id desc ");
         if($ret['conf_value']){
             $adplace[$key]['place'] = iunserializer($ret['conf_value']);
         }
         $content= array();
         $ret2 = pdo_fetchall("select * from ".  tablename("kbwdl_config")." where uniacid='$uniacid' and placeid=202 and confkey='$key' and module='kbwdl_shequzufang' ");
         if(is_array($ret2)){
             foreach($ret2 as $k => $val){
                 if(! empty($val['conf_value'])){
                     $v = iunserializer($val['conf_value']);
                     $v['thumb'] = tomedia($v['image']); 
                     $v['image'] = tomedia($v['image']);
                     $v['url'] = trim($v['url']);
                     $content[] = $v; 
                 }
                 
             }
         }
          $adplace[$key]['content'] = $content;
     }
     /*其他参数*/
     $ret2 = pdo_fetch("select * from ".  tablename("kbwdl_config")." where uniacid='$uniacid' and placeid=11 and module='kbwdl_shequzufang'");     
     $adplace['confmenu'] = iunserializer($ret2['conf_value']);
     if(!isset($adplace['confmenu']['show_footer'])){
         $adplace['confmenu']['show_footer'] = 0;
     }
     if(!isset($adplace['confmenu']['yongjin_name']) || empty($adplace['confmenu']['yongjin_name']) ){
         $adplace['confmenu']['yongjin_name'] = '个人佣金';
     }
      if(!isset($adplace['confmenu']['jianmian']) || empty($adplace['confmenu']['jianmian']) ){
         $adplace['confmenu']['jianmian'] = '建面';
     }
     $adplace['copyinfo'] = $this->module['config']['linkmark'];
     /**
      * 获取是否分销
      */
     $adplace['ischarges']= 0;
     $ret2 = pdo_fetch("select * from ".  tablename("kbwdl_config")." where uniacid='$uniacid' and placeid=91 and module='kbwdl_shequzufang'");
     if(!empty($ret2) && $ret2['conf_value']==1){
         $adplace['ischarges']=1;
     }
     /*推广方式*/
     $adplace['batchmethod']= 0;
     $ret2 = pdo_fetch("select * from ".  tablename("kbwdl_config")." where uniacid='$uniacid' and placeid=92 and module='kbwdl_shequzufang'");
     if(!empty($ret2) && $ret2['conf_value']==1){
         $adplace['batchmethod']=1;
     }
     /**
      * 获取默认城市
      */
        $sql = "select * from ". tablename("kbwdl_area")." where uniacid='".$_W['uniacid']."' and type='4' and disabled=0 " ; 
        $all = pdo_fetchall($sql );
        $citys = [];
        if(is_array($all)){
            foreach($all as $key=>$val){
                $citys[$val['id']] = ['id'=>$val['id'],'name'=> $val['name'] ];
            }
        }
        $default_city = pdo_fetchcolumn("select conf_value from ".tablename("kbwdl_config")." where confkey='default_city' and uniacid='$uniacid' and placeid=800 and module='kbwdl_shequzufang'");
        if($this->module['config']['isduocity']==1){
              /*查询个人设置的*/
                    $ucity = pdo_fetchcolumn("select city_id from ".tablename("kbwdl_share_user")." where uniacid='$uniacid' and openid='$openid'");
                    if($ucity){
                        $default_city = $ucity;
                    }
        }
        if($default_city){
            $adplace['citys']['default'] = $citys[$default_city];
        }else{
            $adplace['citys']['default'] = array_pop($citys);
        }
        $adplace['citys']['citys'] = $citys;
        /**/ 
        /*获取 推荐客户的表单选项*/
  
   
     $ret2 = pdo_fetch("select * from ".  tablename("kbwdl_config")." where uniacid='$uniacid' and placeid=14 and module='kbwdl_shequzufang'");     
     $val = iunserializer($ret2['conf_value']);
     $charitem['truename'] = 1;
     $charitem['mobile'] = 1;
     $charitem['city'] = 1;
     $charitem['area'] = 1;
     $charitem['verycard'] = 1;
     $charitem['bankname'] = 1;
     $charitem['beizhu'] = 1;
     
     if(isset($val['per_disabled']) && $val['per_disabled']){
        $charitem['truename'] = (isset($val['charges_truename']) && $val['charges_truename']) ? 1: 0;
        $charitem['mobile'] = (isset($val['charges_mobile']) && $val['charges_mobile']) ? 1: 0;
        $charitem['city'] = (isset($val['charges_city']) && $val['charges_city']) ? 1: 0;
        $charitem['area'] = (isset($val['charges_area']) && $val['charges_area']) ? 1: 0;
        $charitem['verycard'] = (isset($val['charges_verycard']) && $val['charges_verycard']) ? 1: 0;
        $charitem['bankname'] = (isset($val['charges_bankname']) && $val['charges_bankname']) ? 1: 0;
        $charitem['beizhu'] = (isset($val['charges_beizhu']) && $val['charges_beizhu']) ? 1: 0;
     }
     $adplace['charitem'] = $charitem;
     $adplace['lan'] = [];     
     

    $deflan = IA_ROOT."/addons/kbwdl_shequzufang/vender/{$uniacid}.json";
    if(is_file($deflan)){
       $jsonstr = file_get_contents($deflan);
    }else{
        $jsonstr = file_get_contents(IA_ROOT."/addons/kbwdl_shequzufang/vender/language.json");
    }
    if($jsonstr){
         $jsonstr = json_decode($jsonstr,true);
         if(!empty($jsonstr[$uniacid])){
             $adplace['lan'] = $jsonstr[$uniacid];
         }else{
             $adplace['lan'] =  $jsonstr[0];
         }
     }
     
     
     /*输出参数*/
     
     $params = $adplace;

     
}

$this->result(0, '', $params);

?>
